		var retentDayArray=[];
          var editIndex = undefined;
          $('#tt').edatagrid({
           	url:"/channelconfig/retentList?mark="+$('#mark').val(),
            onClickRow: function(index){
            	 if($('#mark').val()==''){return};
                 if(index!=editIndex){
                     editIndex = index;
                  }
             },
             onLoadSuccess:function(data){
             	$(this).datagrid('enableDnd');
             	retentDayArray=[];

             	if(data.rows.length==0){
             		if($('#mark').val()==''){
             			 $('#tt').datagrid({
 	                        url:'',
 	                        data:''
             			 }); 
             		}else{
                   	 var data1 = [
                	              {"retentDay": "1","referenceRate": "68.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "2","referenceRate": "58.7",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "3","referenceRate": "43.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "4","referenceRate": "39.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "5","referenceRate": "35.5",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "6","referenceRate": "31.9",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "7","referenceRate": "30.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "8","referenceRate": "24.6",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "9","referenceRate": "22.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "10","referenceRate": "20.3",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "11","referenceRate": "18.1",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "12","referenceRate": "17.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "13","referenceRate": "13.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "14","referenceRate": "12.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "15","referenceRate": "12.1",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "16","referenceRate": "7.6",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "17","referenceRate": "5.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "18","referenceRate": "4.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "19","referenceRate": "4.1",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "20","referenceRate": "3.9",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "21","referenceRate": "3.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "22","referenceRate": "2.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "23","referenceRate": "2.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "24","referenceRate": "2.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "25","referenceRate": "1.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "26","referenceRate": "0.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "27","referenceRate": "0.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "28","referenceRate": "0.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "29","referenceRate": "0.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "30","referenceRate": "0.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "31","referenceRate": "68.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "32","referenceRate": "58.7",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "33","referenceRate": "43.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "34","referenceRate": "39.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "35","referenceRate": "35.5",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "36","referenceRate": "31.9",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "37","referenceRate": "30.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "38","referenceRate": "24.6",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "39","referenceRate": "22.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "40","referenceRate": "68.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "41","referenceRate": "68.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "42","referenceRate": "58.7",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "43","referenceRate": "43.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "44","referenceRate": "39.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "45","referenceRate": "35.5",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "46","referenceRate": "31.9",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "47","referenceRate": "30.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "48","referenceRate": "24.6",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "49","referenceRate": "22.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "50","referenceRate": "68.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "51","referenceRate": "68.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "52","referenceRate": "58.7",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "53","referenceRate": "43.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "54","referenceRate": "39.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "55","referenceRate": "35.5",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "56","referenceRate": "31.9",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "57","referenceRate": "30.8",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "58","referenceRate": "24.6",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "59","referenceRate": "22.2",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'},
                	              {"retentDay": "60","referenceRate": "68.4",'retentRate':'','brushRate':'','exetimes':'1','priority':'0'}
                	          ];
             			$('#tt').datagrid({
 	                        url:'',
 	                        data:data1
             			 }); 
             			
             		}
            	}else{
                  	$.each(data.rows,function(index,mod){
                		retentDayArray.push(mod.retentDay)
                	})
            	}
             },
             onBeforeSave:function(index){
            	 var retentDayVal=$("td[field='retentDay'] input").val();
            	 var retentRateVal=$("td[field='retentRate'] input").val();
            	 var exetimesVal=$("td[field='exetimes'] input").val();
            	 var priority=$("td[field='priority'] input").val();
            	 if(retentDayVal==''){
            		 return false; 
            	 }
            	 if(retentRateVal==''){
            		 
            		 return false; 
            	 }
            	 if(exetimesVal==''){
            		
            		 return false; 
            	 }
            	 
            	 if(priority==''){
             		
            		 return false; 
            	 }
             }
          });
         //查询
         function doSearch(){
          	$('#tt').edatagrid({
          		url:"/channelconfig/retentList?mark="+$('#mark').val()});
         }

		function addExecTimes(){
			var mark=$('#mark').val();
			showMyWindow('留存配置 | 次数', '/channelconfig/retentExecTimesList?mark='+mark, 800, 600);
		}

		function resetTimes() {
			var mark=$('#mark').val();
			$.messager.confirm('温馨提醒', '你确定重置吗？', function(r) {
				if (r) {
					$.get('/channelconfig/resetTimes?mark=' + mark, function(data) {
						doSearch();
					});
				}
			});
		}


		function resetPri() {
			var mark=$('#mark').val();
			$.messager.confirm('温馨提醒', '你确定重置吗？', function(r) {
				if (r) {
					$.get('/channelconfig/resetPri?mark=' + mark, function(data) {
						doSearch();
					});
				}
			});
		}

		function resetBrush() {
			var mark=$('#mark').val();
			$.messager.confirm('温馨提醒', '你确定重置吗？', function(r) {
				if (r) {
					$.get('/channelconfig/resetBrush?mark=' + mark, function(data) {
						doSearch();
					});
				}
			});
		}

         //添加
         function addRow(){
         	var markId=$('#mark').val();
         	if(markId==''){return}
         	var file='/resources/js/easyui/datagrid-dnd.js';
         	$('#tt').edatagrid('appendRow', {
         		mark:markId,    
                retentDay:'',
                exetimes:'1',
                priority:'0'
            });
            $('#tt').datagrid('enableDnd');
         }

          //保存
		function saveRow(){
		    var markId=$('#mark').val();
         	if(markId==''){return}
            var newRow=[];
            var arrayLen=0;
            $('#tt').edatagrid('saveRow')
            var initRow=$("#tt").datagrid('getRows');
 		  	$.each(initRow,function(index,mod){
		  		if(mod.retentRate===''||mod.exetimes==''||mod.retentDay==''||mod.exetimes==0||mod.retentRate==0){
			  		
		  		}else{
		  			var	array={};
			  		array={retentRate:mod.retentRate,retentDay:mod.retentDay,exetimes:mod.exetimes,copyMark:mod.mark,priority:mod.priority,brushRate:mod.brushRate,mark:markId};
			  		newRow.push(array);
			  		arrayLen=newRow.length;
		  		}
		  		
		  	})
		  
		  	$.ajax({
		  		url:'/channelconfig/saveRetent',
		  		type:'post',
		  		dataType:"json",
		  		data:JSON.stringify(newRow),
		  		contentType:'application/json',
		  		success:function(){
		  			jQuery.messager.alert('提示:','成功保存'+arrayLen+'条数据!'); 
		  			doSearch();
		  		}
		  	})
            
        }
        //删除
        function remove(){
            //if (editIndex == undefined){return}
            //var row = $('#tt').datagrid('getSelected');
            //var array={retentRate:row.retentRate,retentDay:row.retentDay,exetimes:row.exetimes,mark:row.mark,priority:row.priority}
        	//$.ajax({
		  		//url:'/channelconfig/deleteRetent',
		  		//type:'post',
		  		//dataType:"json",
		  		//data:JSON.stringify(array),
		  		//contentType:'application/json',
		  		//success:function(){
		  			//jQuery.messager.alert('提示:','删除成功!'); 
		  			//editIndex = undefined;
		  			//doSearch();
		  		//}
		  	//})
        	
		  	var rows = $('#tt').edatagrid('getChecked');
		  	var arr = [];
		  	for (var i=0;i<rows.length;i++) {
		  		var channelRetentConfig = {};
		  		channelRetentConfig['retentRate'] = rows[i].retentRate;
				channelRetentConfig['brushRate'] = rows[i].brushRate;
		  		channelRetentConfig['retentDay'] = rows[i].retentDay;
		  		channelRetentConfig['exetimes'] = rows[i].exetimes;
		  		channelRetentConfig['mark'] = rows[i].mark;
		  		channelRetentConfig['priority'] = rows[i].priority;
		  		arr.push(channelRetentConfig)
		  	}
		  	
		  	$.ajax({
		  		headers: {
	                'Accept': 'application/json',
	                'Content-Type': 'application/json'
	            },
		  		url:'/channelconfig/batchDelete',
		  		type:'POST',
		  		data: JSON.stringify(arr),
		  		async: true,
	            dataType: "json",
		  		success:function(){
	  				jQuery.messager.alert('提示:','删除成功!'); 
		  			doSearch();
		  		}
		  	})
        }
        
        //全选
        function selectAll(){
        	 $('#tt').datagrid('selectAll');
        }
        //输入框限制为数字
		$(document).on("keyup afterpaste","td[field='retentDay'] input","td[field='exetimes'] input",function(){
			this.value=this.value.replace(/\D/g,'');
		})
		//占比输入框限制，最大为100且只最多能有两位小数点 
		$(document).on("keyup afterpaste","td[field='retentRate'] input",function(e){
				 this.value = this.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符   
				 this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的   
				 this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");  
				 this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数   
				 if(this.value.indexOf(".")< 0 && this.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额  
					 this.value= parseFloat(this.value);  
				 }  
				 if(this.value>100){
					 this.value = 100;
				 }
		})

		$(document).on("keyup afterpaste","td[field='brushRate'] input",function(e){
			this.value = this.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符
			this.value = this.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的
			this.value = this.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
			this.value = this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数
			if(this.value.indexOf(".")< 0 && this.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
				this.value= parseFloat(this.value);
			}
			if(this.value>100){
				this.value = 100;
			}
		})
		
		$(document).on('blur', '.datagrid-view td[field=retentDay] input', function(){
			var inputVal=this.value;
			$.each(retentDayArray,function(index,mod){
				if(mod==inputVal){
					inputVal='';
					jQuery.messager.alert('提示:','留存天数不能重复!');	
				}
			})
			$(this).val(inputVal);
		});
  
	  
		